package exercise10;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;



public class Exercise15_05 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        GridPane pane=new GridPane();

        TextField total=new TextField();
        TextField rate=new TextField();
        TextField year=new TextField();
        TextField future=new TextField();
        Button button=new Button("计算");

        pane.add(new Label("投资值"),0,0);
        pane.add(total,1,0);
        pane.add(new Label("年数"),0,1);
        pane.add(year,1,1);
        pane.add(new Label("年利率（%）"),0,2);
        pane.add(rate,1,2);
        pane.add(new Label("未来值"),0,3);
        pane.add(future,1,3);
        pane.add(button,0,4);

        button.setOnAction(event -> {
            int year_text=Integer.parseInt(year.getText());
            double rate_text=Double.parseDouble(rate.getText())/1200;
            double total_text=Double.parseDouble(total.getText());

            future.setText(String.valueOf(total_text * Math.pow(1 + rate_text, year_text * 12)));
        });

        primaryStage.setTitle("计算未来值");
        primaryStage.setScene(new Scene(pane,300,300));
        primaryStage.show();

    }
}
